//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Windows.Media.Media3D;

namespace OpenLS.Chart.UI
{
    class ConeToMaxGeometryFactory: ConeGeometryFactoryBase
    {
        public ConeToMaxGeometryFactory(BarDirection direction): base(direction)
        {
            
        }
        internal override Point3D GetPosition(double theta, double value)
        {
            double ratio = (TotalValueBounds.High - value) / TotalValueBounds.Delta;
            Bounds categoryBounds = GetCategoryBounds(Bounds);
            double category = categoryBounds.Mid + ratio * categoryBounds.Delta / 2 * Math.Cos(theta);
            double z = Bounds.Z.Mid + ratio * Bounds.Z.Delta / 2 * Math.Sin(theta);
            return CreatePoint(value, category, z);
        }


        protected override void AddTop(MeshGeometry3D mesh)
        {
            Bounds topBounds = TotalValueBounds;
            double ratio = (topBounds.High - GetValueBounds(Bounds).High) / TotalValueBounds.Delta / 2;
            Bounds fullCategoryBounds = GetCategoryBounds(Bounds);
            Bounds categoryBounds = UI.Bounds.Create(fullCategoryBounds.Mid - fullCategoryBounds.Delta * ratio, fullCategoryBounds.Mid + fullCategoryBounds.Delta * ratio);
            Bounds zBounds = UI.Bounds.Create(Bounds.Z.Mid - Bounds.Z.Delta * ratio, Bounds.Z.Mid + Bounds.Z.Delta * ratio);
            int dir;
            if (Direction == BarDirection.Column)
                dir = 1;
            else
            {
                dir = -1;
            }
            Tessellator.Tessellate(mesh, CreateVector(1, 0, 0), DiskTessellator.GetPoints(GetValueBounds(Bounds).High, categoryBounds, zBounds, dir, 32, Direction));
        }

    }
}
